package com.zy.explore.sys.infrastructure.third.dingtalk.feign;

import com.zy.explore.sys.infrastructure.third.dingtalk.frm.AttendListFrm;
import com.zy.explore.sys.infrastructure.third.dingtalk.frm.DeptUserIdListFrm;
import com.zy.explore.sys.infrastructure.third.dingtalk.frm.GetDeptDetailFrm;
import com.zy.explore.sys.infrastructure.third.dingtalk.frm.GetDeptUserFrm;
import com.zy.explore.sys.infrastructure.third.dingtalk.frm.GetDingDeptListFrm;
import com.zy.explore.sys.infrastructure.third.dingtalk.frm.GetSubDeptIdFrm;
import com.zy.explore.sys.infrastructure.third.dingtalk.frm.GetTokenFrm;
import com.zy.explore.sys.infrastructure.third.dingtalk.frm.GetUserDetailFrm;
import com.zy.explore.sys.infrastructure.third.dingtalk.frm.TokenFrm;
import com.zy.explore.sys.infrastructure.third.dingtalk.vo.DingAttendListVO;
import com.zy.explore.sys.infrastructure.third.dingtalk.vo.DingDeptDetailVO;
import com.zy.explore.sys.infrastructure.third.dingtalk.vo.DingDeptListVO;
import com.zy.explore.sys.infrastructure.third.dingtalk.vo.DingTokenResultVO;
import com.zy.explore.sys.infrastructure.third.dingtalk.vo.DingUserDetailVO;
import com.zy.explore.sys.infrastructure.third.dingtalk.vo.DingUserListVO;
import com.zy.explore.sys.infrastructure.third.dingtalk.vo.ListUserByDeptIdResultVO;
import com.zy.explore.sys.infrastructure.third.dingtalk.vo.ListUserByDeptIdVO;
import com.zy.explore.sys.infrastructure.third.dingtalk.vo.SubDeptIdListVO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.validation.Valid;

/**
 * description 钉钉服务
 *
 * 详见：https://developers.dingtalk.com/document/app/server-api-overview
 *
 * @author 🇨🇳中国印🇨🇳
 * @date 2021年07月08日 00:53
 */
@FeignClient(name = "DINGTALK-SERVICE", url = "https://oapi.dingtalk.com")
public interface DingTalkFeign {

    /**
     * 获取钉钉令牌
     *
     * 详见：https://developers.dingtalk.com/document/app/obtain-orgapp-token
     *
     * @param frm    钉钉token获取请求参数
     * @return {@link DingTokenResultVO}
     */
    @GetMapping("/gettoken")
    DingTokenResultVO getToken(@SpringQueryMap @Valid GetTokenFrm frm);

    /**
     * 获取用户详情
     *
     * 详见：https://developers.dingtalk.com/document/app/queries-user-details
     *
     * @param frm 查询参数
     * @return {@link DingUserDetailVO}
     */
    @GetMapping("/user/get")
    DingUserDetailVO getUserDetail(@SpringQueryMap @Valid GetUserDetailFrm frm);

    /**
     * 获取部门详情
     *
     * 详见：https://developers.dingtalk.com/document/app/queries-department-details
     *
     * @param frm 部门ID请求对象
     * @return {@link DingDeptDetailVO}
     */
    @GetMapping("/department/get")
    DingDeptDetailVO getDeptDetail(@SpringQueryMap GetDeptDetailFrm frm);

    /**
     * 查询钉钉部门集合
     *
     * 详见：https://developers.dingtalk.com/document/app/obtain-the-department-list
     *
     * @param frm 查询参数
     * @return {@link DingDeptListVO}
     */
    @GetMapping("/department/list")
    DingDeptListVO getDingTalkDeptList(@SpringQueryMap @Valid GetDingDeptListFrm frm);

    /**
     * 查询钉钉部门的子部门
     *
     * 详见：https://developers.dingtalk.com/document/app/obtain-a-sub-department-id-list-v2
     *
     * @param token 调用凭证
     * @param frm   请求体参数
     * @return {@link SubDeptIdListVO}
     */
    @PostMapping("/topapi/v2/department/listsubid")
    SubDeptIdListVO getDingSubDeptIdList(@SpringQueryMap TokenFrm token, @RequestBody @Valid GetSubDeptIdFrm frm);

    /**
     * 查询部门用户集合
     *
     * 详见: https://developers.dingtalk.com/document/app/obtain-department-members
     *
     * @param frm 查询参数
     * @return {@link DingUserListVO}
     */
    @GetMapping("/user/simplelist")
    DingUserListVO getDeptUserList(@SpringQueryMap @Valid GetDeptUserFrm frm);

    /**
     * 获取用户打卡考勤列表
     *
     * 详情：https://developers.dingtalk.com/document/app/open-attendance-clock-in-data
     *
     * @param token 访问令牌
     * @param frm   请求体参数
     * @return {@link DingAttendListVO}
     */
    @PostMapping("/attendance/list")
    DingAttendListVO getAttendList(@SpringQueryMap TokenFrm token, @RequestBody @Valid AttendListFrm frm);

    /**
     * 获取钉钉部门员工ID集合
     *
     * @param token 访问令牌
     * @param frm   部门ID请求对象
     * @return {@link ListUserByDeptIdVO}
     */
    @PostMapping("/topapi/user/listid")
    ListUserByDeptIdResultVO getDeptUserIdList(@SpringQueryMap TokenFrm token, @RequestBody @Valid DeptUserIdListFrm frm);
}
